package com.sunfeng.netty.atguigu.buf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import java.nio.charset.StandardCharsets;

/**
 * @author sunfeng
 */
public class NettyByteBuf02 {
    public static void main(String[] args) {
        ByteBuf byteBuf = Unpooled.copiedBuffer("hello,world!",StandardCharsets.UTF_8);
        if (byteBuf.hasArray()) {
            byte[] bytes = byteBuf.array();
            System.out.println(new String(bytes, StandardCharsets.UTF_8));

            System.out.println(byteBuf);
            System.out.println(byteBuf.arrayOffset());

            System.out.println(byteBuf.readerIndex());
            // 12
            System.out.println(byteBuf.writerIndex());
            // 64
            System.out.println(byteBuf.capacity());
            // 返回104   h 的ask码是104
            // System.out.println(byteBuf.readByte());
            System.out.println(byteBuf.getCharSequence(0,4,StandardCharsets.UTF_8));
//            for (int i = 0; i < byteBuf.capacity(); i++) {
//                System.out.println((char)byteBuf.getByte(i));
//            }

        }

    }
}
